package com.inspire.myapp;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import com.codename1.io.Externalizable;

public class peripherique implements Externalizable {

	public String id=null;
	public String nom=null;
	public String lecture_type="";
	public String ecriture_type="";
	public String uuid=null;
	public categorie categorie =null;
	public tag[] tags =null;
	public box box=null;
	public String etat="";
	public String expr1="";
	public String expr2="";
	public String expr3="";
	
	
	public peripherique() {
		
	}

	@Override
	public int getVersion() {
		return 0;
	}


	@Override
	public void externalize(DataOutputStream out) throws IOException {

		out.writeUTF(this.id);
		out.writeUTF(this.nom);
		out.writeUTF(this.lecture_type);
		out.writeUTF(this.ecriture_type);
		out.writeUTF(this.categorie.id);
		out.writeUTF("tags");
		out.writeInt(this.tags.length);
		for (tag t : this.tags) {
			out.writeUTF(t.id);
		}

		out.writeUTF(this.box.id);
		out.writeUTF(this.uuid);
		
		
		
	}


	@Override
	public void internalize(int version, DataInputStream in) throws IOException {
		switch (version) {
		case 0:
			this.id=in.readUTF();
			this.nom=in.readUTF();
			this.lecture_type=in.readUTF();
			this.ecriture_type=in.readUTF();
			
			this.categorie=(categorie) objets.obj.categories.get(in.readUTF());
			if (in.readUTF().equals("tags")) {
				int nbtag=in.readInt();
				this.tags=new tag[nbtag];
				for (int i = 0; i < nbtag; i++) {
					this.tags[i]=(tag) objets.obj.tags.get(in.readUTF());
				}
			}
			this.box=(box) objets.obj.boxs.get(in.readUTF());
			this.uuid=in.readUTF();
			
			break;
		default:
			break;
		}
	}

	@Override
	public String getObjectId() {
		return "peripherique_"+this.uuid;
	}
}
